goog.provide('imc.CharCounter');

imc.CharCounter = function (opt) { //Constructor
    /*\\Behavior : --------------------------------- */
    this.opt={
        NAME_TABLE:""
        ,uriSrvGetInformationColumns:"Services/User.svc/GetInformationColumns"
        ,columnName: ""
    }
    $().extend(this.opt,opt);
    this.getColumnsInfo();
    /*//Behavior : --------------------------------- */
} //Fin constructor

//Atributos Público************************************************
imc.CharCounter.prototype.opt = null;

imc.CharCounter.prototype.getColumnsInfo = function () {
    $.ajax({
        type: "POST"
        , url: this.opt.uriSrvGetInformationColumns
        , data: '{"NAME_TABLE":"' + this.opt.columnName + '"}'
        , contentType: "application/json; charset=utf-8"
        , dataType: "json"
        , success: function (data) {
            for (var i in data.GetInformationColumnsResult) {
                var COLUMN_NAME = data.GetInformationColumnsResult[i].COLUMN_NAME;
                var CHARACTER_MAXIMUM_LENGTH = data.GetInformationColumnsResult[i].CHARACTER_MAXIMUM_LENGTH;
                $("#"+ COLUMN_NAME ).parent().append('<span id="' + COLUMN_NAME + i + '" style="margin-left:2px;"></span> Caracteres Restantes');
                new goog.ui.CharCounter(document.getElementById(COLUMN_NAME), document.getElementById(COLUMN_NAME + i),
                    CHARACTER_MAXIMUM_LENGTH);
            }
        }
        , error: function (result) {
            alert('Error al recargar la tabla de roles ' + result.status + ' ' + result.statusText);
        }
    });
}

//this.c1 = new goog.ui.CharCounter(document.getElementById('nombreUsuario'), document.getElementById('counter1'), 50);
